package com.wb.fw;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.MotionEvent;

import com.wb.oldwomen.GameScene;
import com.wb.oldwomen.R;
import com.wiyun.engine.nodes.Director;
import com.wiyun.engine.nodes.Menu;
import com.wiyun.engine.nodes.MenuItemLabel;
import com.wiyun.engine.nodes.Scene;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.transitions.RightTopTilesShrinkOutTransition;
import com.wiyun.engine.transitions.TransitionScene;
import com.wiyun.engine.types.WYSize;
import com.wiyun.engine.utils.TargetSelector;

public class SplashScene extends Scene implements IConstants {
	public SplashScene() {

		WYSize s = Director.getInstance().getWindowSize();

		Global.sWYSize = s;
//		System.out.println("-----------");
//		System.out.println("["+s.width+"x"+s.height+"]");

		float sh = s.height/BASE_VERSION_SCREEN_HEIGHT;
		float sw = s.width/BASE_VERSION_SCREEN_WIDTH;

		Global.half_w = (int)(s.width/2);
		Global.half_h = (int)(s.height/2);

		if(sh < sw)
		{
			Global.sScaleRate = sh;
			Global.sStartX = (s.width - BASE_VERSION_SCREEN_WIDTH *sh) / 2;
			Global.sStartY = s.height;

			Global.sEndX = s.width - Global.sStartX;
			Global.sEndY = 0;
		}
		else
		{
			Global.sScaleRate = sw;
			Global.sStartY = s.height - (s.height - BASE_VERSION_SCREEN_HEIGHT *sw) / 2;
			Global.sStartX = 0;

			Global.sEndY = s.height - Global.sStartY;
			Global.sEndX = s.width;
		}
		System.out.println("[sw="+sw+",sh="+sh+"]");
		System.out.println("SHScaleRate = " + Global.sScaleRate);
		System.out.println("Start["+Global.sStartX+","+Global.sStartY+"]");
		System.out.println("End["+Global.sEndX+","+Global.sEndY+"]");

	    Sprite bgsp = Sprite.make(R.drawable.load);
	    bgsp.setPosition(s.width / 2, s.height / 2);
	    bgsp.setScale(Global.sScaleRate);
	    bgsp.autoRelease();
	    addChild(bgsp);

        setTouchEnabled(false);
		setKeyEnabled(true);
		setMultiTouchClickable(false);
	    autoRelease(true);

	    schedule(new TargetSelector(this, "onStart(float)", new Object[]{0}), 0.1f);
//	    scheduleOnce(new TargetSelector(this, "onStart(float)", new Object[]{0}), 0.2f);
    }
	
	public void onStart(float detal) {
		//TODO:加载数据些。
		
		Scene scene = new GameScene();
		Director.getInstance().replaceScene((scene));
    }

    public void onQuit() {
        Director.getInstance().end();
    }

//    @Override
//	public boolean wyTouchesBegan(MotionEvent event) {
//    	//触摸切换场景
//    	onStart(0);
//		return true;
//	}

//    @Override
//	public boolean wyKeyDown(KeyEvent event) {
//
//    	//handle back key
//    			if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
//    				AlienInvasionActivity.sInstance.runOnUiThread(new Runnable() {
//
//    					@Override
//    					public void run() {
//    						// TODO Auto-generated method stub
//    						new AlertDialog.Builder(Director.getInstance().getContext())
//    						.setMessage("Exit Game?")
//    						.setPositiveButton("Yes",
//    								new DialogInterface.OnClickListener() {
//    									@Override
//    									public void onClick(
//    											DialogInterface dialog,
//    											int which) {
//    										System.exit(1);
//    									}
//    								})
//    						.setNegativeButton("No",
//    								new DialogInterface.OnClickListener() {
//    									public void onClick(
//    											DialogInterface dialog,
//    											int which) {
//    									}
//    								}).show();
//    					}
//    				});
//
//
//    				return false;
//    			}
//    	return true;
//    }

}
